package com.buddy.design.pattern._05strategy.pay;

import com.buddy.design.pattern._05strategy.pay.payport.*;

import java.util.HashMap;

public class PayStrategy {
    public static final String ALI_PAY = "ALI";
    public static final String JD_PAY = "JD";
    public static final String WECHART_PAY = "WeChart";
    public static final String UNION_PAY = "UNION";
    public static final String DEFAULT_PAY = ALI_PAY;

    private static HashMap<String, Payment> payStrategy = new HashMap<>();

    static {
        payStrategy.put(ALI_PAY, new AliPay());
        payStrategy.put(JD_PAY, new JDPay());
        payStrategy.put(WECHART_PAY, new WeChatPay());
        payStrategy.put(UNION_PAY, new UnionPay());
    }

    public static Payment getPayment(String paymentKey) {
        if (payStrategy.containsKey(paymentKey)) {
            return payStrategy.get(paymentKey);
        }
        return payStrategy.get(DEFAULT_PAY);
    }
}
